package org.kazuhiko.rpg.server.net.packet;

public final class PacketDefinition
{
	private final int id;
	
	private final String name;
	
	private final PacketField[] fields;
	
	private final transient int length;
	
	public PacketDefinition( int id, String name, PacketField[] fields )
	{
		this.id = id;
		this.name = name;
		this.fields = fields;
		
		int leng = 0;
		for( PacketField field : fields )
		{
			leng += field.getType().getLength();
		}
		
		this.length = leng;
	}
	
	private Object readResolve()
	{
		return new PacketDefinition( id, name, fields );
	}
	
	public int getId()
	{
		return id;
	}
	
	public String getName()
	{
		return name;
	}
	
	public PacketField[] getFields()
	{
		return fields;
	}
	
	public int getLength()
	{
		return length;
	}
}
